<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Adds a file to a ZIP archive from the given path</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="ziparchive.addemptydir.html">ZipArchive::addEmptyDir</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="ziparchive.addfromstring.html">ZipArchive::addFromString</a></div>
 <div class="up"><a href="class.ziparchive.html">ZipArchive</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="ziparchive.addfile" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ZipArchive::addFile</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.2.0, PECL zip &gt;= 1.1.0)</p><p class="refpurpose"><span class="refname">ZipArchive::addFile</span> &mdash; <span class="dc-title">Adds a file to a ZIP archive from the given path</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-ziparchive.addfile-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>ZipArchive::addFile</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$localname</code><span class="initializer"> = <strong><code>NULL</code></strong></span></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$start</code><span class="initializer"> = 0</span></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$length</code><span class="initializer"> = 0</span></span>
  ]]] )</div>

  <p class="para rdfs-comment">
   Adds a file to a ZIP archive from a given path.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-ziparchive.addfile-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">filename</code></em></dt>

     <dd>

      <p class="para">
       The path to the file to add.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">localname</code></em></dt>

     <dd>

      <p class="para">
       If supplied, this is the local name inside the ZIP archive that will override the <em><code class="parameter">filename</code></em>.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">start</code></em></dt>

     <dd>

      <p class="para">
       This parameter is not used but is required to extend <a href="class.ziparchive.html" class="classname">ZipArchive</a>.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">length</code></em></dt>

     <dd>

      <p class="para">
       This parameter is not used but is required to extend <a href="class.ziparchive.html" class="classname">ZipArchive</a>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-ziparchive.addfile-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-ziparchive.addfile-examples">
  <h3 class="title">范例</h3>
    <p class="para">
     This example opens a ZIP file archive
     <var class="filename">test.zip</var> and add
     the file <var class="filename">/path/to/index.txt</var>.
     as <var class="filename">newname.txt</var>.
    </p>
    <div class="example" id="example-755">
     <p><strong>Example #1 Open and extract</strong></p>
     <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$zip&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">ZipArchive</span><span style="color: #007700">;<br />if&nbsp;(</span><span style="color: #0000BB">$zip</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">open</span><span style="color: #007700">(</span><span style="color: #DD0000">'test.zip'</span><span style="color: #007700">)&nbsp;===&nbsp;</span><span style="color: #0000BB">TRUE</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$zip</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addFile</span><span style="color: #007700">(</span><span style="color: #DD0000">'/path/to/index.txt'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'newname.txt'</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$zip</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">close</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'ok'</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'failed'</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
     </div>

    </div>
   </div>

 <div class="refsect1 notes" id="refsect1-ziparchive.addfile-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    When a file is set to be added to the archive, PHP will attempt to lock 
    the file and it is only released once the ZIP operation is done. In short, 
    it means you can first delete an added file after the archive is closed.
   </p>
  </p></blockquote>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="ziparchive.addemptydir.html">ZipArchive::addEmptyDir</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="ziparchive.addfromstring.html">ZipArchive::addFromString</a></div>
 <div class="up"><a href="class.ziparchive.html">ZipArchive</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
